package com.huizhonglm.diap.ui.wallet;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bruce.common.utils.EmptyUtil;
import com.huizhonglm.diap.R;
import com.huizhonglm.diap.api.model.wallet.RevenueInfo;

import java.util.List;

/**
 * 附近商品列表适配器
 *
 * @author LiXiaoLong
 * @version 1.0
 * @since 2016-03-07 13:42
 */
public class RcmRevenueAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private List<RevenueInfo> data;

    public RcmRevenueAdapter(Context context, List<RevenueInfo> data) {
        this.inflater = LayoutInflater.from(context);
        this.data = data;
    }

    public void setData(List<RevenueInfo> data) {
        this.data = data;
    }

    @Override
    public int getCount() {
        return EmptyUtil.isEmpty(data) ? 0 : data.size();
    }

    @Override
    public RevenueInfo getItem(int position) {
        return EmptyUtil.isEmpty(data) ? null : data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        ViewHolder holder;
        if (view == null) {
            holder = new ViewHolder();
            view = inflater.inflate(R.layout.item_rcm_revenue, parent, false);
            holder.date = (TextView) view.findViewById(R.id.date_txt);
            holder.revenue_jl_count = (TextView) view.findViewById(R.id.revenue_jl_count);
            holder.revenue_jl_money = (TextView) view.findViewById(R.id.revenue_jl_money);
            holder.revenue_fh_count = (TextView) view.findViewById(R.id.revenue_fh_count);
            holder.revenue_fh_money = (TextView) view.findViewById(R.id.revenue_fh_money);

            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        RevenueInfo item = getItem(position);
        holder.date.setText(item.getDate());
        holder.revenue_jl_count.setText(item.getRecommendedProfitCount() + "");
        holder.revenue_jl_money.setText(item.getRecommendedProfit() + "");
        holder.revenue_fh_count.setText(item.getBonusProfitCount() + "");
        holder.revenue_fh_money.setText(item.getBonusProfit() + "");
        return view;
    }

    private class ViewHolder {
        private TextView date;
        private TextView revenue_jl_count;
        private TextView revenue_jl_money;
        private TextView revenue_fh_count;
        private TextView revenue_fh_money;
    }
}
